/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DBLogin.java
 *
 * Created on 2008-12-08, 16:09:11
 */

package DBBrowser;

import DBBrowser_pack.DBManager;

/**
 *
 * @author Dom
 */
public class DBLogin extends javax.swing.JPanel implements java.io.Serializable{

    /** Creates new form DBLogin */
    public DBLogin() {
        initComponents();
   //manager=new DBManager();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        adres = new javax.swing.JTextField();
        baza = new javax.swing.JTextField();
        password = new javax.swing.JPasswordField();
        port = new javax.swing.JTextField();
        login = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        adres.setToolTipText("Adres bazy danych");
        adres.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adresActionPerformed(evt);
            }
        });

        baza.setToolTipText("Nazwa bazy danych z którą chcesz się połączyć");

        password.setToolTipText("Hasło");

        port.setToolTipText("Port na którym działa baza");

        login.setToolTipText("Login");

        jLabel1.setText("Adres:");

        jLabel2.setText("Port:");

        jLabel3.setText("Baza:");

        jLabel4.setText("Login:");

        jLabel5.setText("Hasło:");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(adres, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE)
                        .addGap(4, 4, 4)
                        .addComponent(port, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(baza, javax.swing.GroupLayout.DEFAULT_SIZE, 429, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 29, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(login, javax.swing.GroupLayout.DEFAULT_SIZE, 209, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel1))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(adres)
                        .addComponent(port)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE))
                    .addComponent(baza, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 24, Short.MAX_VALUE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(password, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                        .addComponent(login)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void adresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adresActionPerformed
        setAdres("");
       
        // TODO add your handling code here:
    }//GEN-LAST:event_adresActionPerformed
//public String tabele[]={"","",""};

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField adres;
    private javax.swing.JTextField baza;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JTextField login;
    private javax.swing.JPasswordField password;
    private javax.swing.JTextField port;
    // End of variables declaration//GEN-END:variables

    /**
     * @return the adres
     */
    public String getAdres() {
        return adres.getText();
    }

    /**
     * @param adres the adres to set
     */
    public void setAdres(String adres) {
        this.adres.setText(adres);
    }

    /**
     * @return the baza
     */
    public String getBaza() {
        return baza.getText();
    }

    /**
     * @param baza the baza to set
     */
    public void setBaza(String baza) {
        this.baza.setText(baza);
    }

    /**
     * @return the login
     */
    public String getLogin() {
        return login.getText();
    }

    /**
     * @param login the login to set
     */
    public void setLogin(String login) {
        this.login.setText(login);
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password.getText();
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password.setText(password);
    }

    /**
     * @return the port
     */
    public String getPort() {
        return port.getText();
    }

    /**
     * @param port the port to set
     */
    public void setPort(String port) {
        this.port.setText(port);
    }
    public void setTextFieldsBg(java.awt.Color c){
        adres.setBackground(c);
         port.setBackground(c);
          baza.setBackground(c);
           login.setBackground(c);
            password.setBackground(c);
    }
     public void setTextFieldsFg(java.awt.Color c){
       adres.setForeground(c);
        port.setForeground(c);
         baza.setForeground(c);
         login.setForeground(c);
         password.setForeground(c);
    }
public void polacz(){
manager=new DBManager(adres.getText(),port.getText(),baza.getText(),login.getText(),password.getText());
//for(int i=0;i<3;i++)
 //   tabele[i]=manager.ask(i);
}
public void rozlacz(){
   manager.finalize();
}
public String[] tabele(){
    String[] table=new String[manager.ask().size()];
    for(int i=0;i<manager.ask().size();i++)
    table[i]=manager.ask().elementAt(i);
return table;
}
public String[] widoki(){
    String[] table=new String[manager.askViews().size()];
    for(int i=0;i<manager.askViews().size();i++)
    table[i]=manager.askViews().elementAt(i);
return table;
}
public String[] AllTables(){
    String[] table=new String[manager.askAllTables().size()];
    for(int i=0;i<manager.askAllTables().size();i++)
    table[i]=manager.askAllTables().elementAt(i);
return table;
}
public String[] AllViews(){
    String[] table=new String[manager.askAllViews().size()];
    for(int i=0;i<manager.askAllViews().size();i++)
    table[i]=manager.askAllViews().elementAt(i);
return table;
}
public String[] ColumnNames(String table){
    return manager.columnNames(table);
}
public Object[][] QuerryTable(String table){
    return manager.QueryTable(table);

}
public static DBManager getManager(){
    return manager;
}
private static DBManager manager;
}
